package com.zssj.controller;

import com.zssj.common.utils.IpUtils;
import com.zssj.framework.controller.SuperController;
import com.zssj.framework.responses.ApiResponses;
import com.zssj.model.dto.TokenDTO;
import com.zssj.model.entity.SysUser;
import com.zssj.model.parm.LoginPARM;
import com.zssj.servise.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @项目名: rzccc_home
 * @描述: token前端控制器
 * @作者: 杜文骄
 * @时间: 2020-10-02 08:47
 **/
@Api(tags = {"Token"},description = "用户token操作相关接口")
@RestController
@RequestMapping(value = "/token",produces = {"application/json;charset=UTF-8"})
@Validated
public class TokenController extends SuperController {
    @Autowired
    ISysUserService sysUserService;

    //获取token
    @ApiOperation("获取token")
    @PostMapping("/getToken")
    public ApiResponses<TokenDTO> getToken(@RequestBody @Validated LoginPARM loginPARM) {
        SysUser user = sysUserService.login(loginPARM.getLoginName(), loginPARM.getPassword());
        TokenDTO tokenDTO = sysUserService.getToken(user);
        return success(tokenDTO);
    }


}
